home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Personal Computer World 2009 February
/
PCWFEB09.iso
/
Software
/
Resources
/
Chat & Communication
/
Digsby build 37
/
digsby_setup.exe
/
lib
/
yahoo
/
yfiletransfer.pyo
(
.txt
)
< prev
Wrap
Python Compiled Bytecode
|
2008-10-13
|
7KB
|
208 lines
# Source Generated with Decompyle++
# File: in.pyo (Python 2.5)
from __future__ import with_statement
from httplib import IncompleteRead
FILE_XFER_URL = 'http://filetransfer.msg.yahoo.com:80/notifyft'
PROXY_FILESIZE_LIMIT = 1048576
import common
from traceback import print_exc
from util import threaded, chained_files
from yahoo.yahooutil import filename_from_url
import struct
from StringIO import StringIO
from util.net import HTTPConnProgress
from logging import getLogger
log = getLogger('yahoo.ft')
info = log.info
error = log.error
in_cls = common.IncomingHTTPFileTransfer
out_cls = common.filetransfer.OutgoingFileTransfer
PNG_HEADER = struct.pack('8B', 137, 80, 78, 71, 13, 10, 26, 10)
class YahooHTTPIncoming(in_cls):
def __init__(self, protocol, buddy, url):
in_cls.__init__(self, protocol, buddy, filename_from_url(url), url)
def set_buddy_icon(yahoo, image_data):
log.info('set_buddy_icon %r', yahoo)
YahooIconSender.send_buddy_icon(yahoo, image_data)
class OutgoingYHTTPXfer(out_cls):
direction = 'outgoing'
http_path = '/notifyft'
host = 'filetransfer.msg.yahoo.com:80'
conn_host = 'filetransfer.msg.yahoo.com'
def __init__(self, protocol, buddy = None, fileinfo = None, initiate = True):
out_cls.__init__(self)
if fileinfo is not None:
self.filepath = fpath = fileinfo.files[0]
self.name = fpath.name
self.size = fpath.size
self.buddy = buddy
self.protocol = protocol
self.cancelled = False
if hasattr(fileinfo, 'obj'):
fileinfo.obj.close()
if initiate:
self.initiate_transfer()
def initiate_transfer(self, message = ''):
filesize = self.filepath.size
if filesize > PROXY_FILESIZE_LIMIT:
self.state = self.states.PROXY_XFER_FILESIZE_ERROR
return None
protocol = self.protocol
ydata = protocol.yahoo_packet_v(15, 'filetransfer', 'available', 'away_buddy', protocol.self_buddy.name, 'to', self.buddy.name, 'message', message, 'filename', self.name, 'filesize', filesize, 'filedata', '')
sublen = (struct.unpack('!H', ydata[8:10])[0] - 8 + len(str(filesize))) + 14
ydata = ydata[:8] + struct.pack('!H', sublen - 1) + ydata[10:-2]
self.state = self.states.TRANSFERRING
try:
fileobj = file(self.filepath, 'rb')
except:
print_exc()
self.state = self.states.CONN_FAIL
self.on_error()
self._post_file(ydata, protocol.cookie_str, fileobj = fileobj, filesize = filesize)
def cancel(self):
try:
self.conn.close()
del self.conn
except:
pass
self.cancelled = True
self.state = self.states.CANCELLED_BY_YOU
def _post_file(self, ydata, cookies, fileobj = None, filesize = None):
try:
self.conn = conn = HTTPConnProgress(self.conn_host)
except Exception:
e = None
print_exc()
if not self.cancelled:
self.state = self.states.CONN_FAIL
self.on_error()
return False
conn.putrequest('POST', self.http_path, skip_host = True, skip_accept_encoding = True)
conn.putheader('Cookie', cookies)
conn.putheader('Host', self.host)
conn.putheader('Content-Length', str(len(ydata) + filesize))
conn.putheader('Cache-Control', 'no-cache')
conn.endheaders()
diff = len(ydata) - filesize
try:
if ydata != '':
conn.send_file_cb(chained_files([
ydata,
fileobj]), self._setcompleted, progressDelta = len(ydata))
else:
conn.send_file_cb(fileobj, self._setcompleted)
except:
if not self.cancelled:
print_exc()
self.state = self.states.CONN_FAIL
try:
conn.close()
finally:
try:
fileobj.close()
except:
pass
if self.state != self.states.TRANSFERRING:
return None
self._setcompleted(filesize)
try:
response = conn.getresponse()
respdata = response.read()
status = response.status
log.info('response data %d bytes, status code %s', len(respdata), status)
log.info('response data %s', respdata)
if status != 200:
self.state = self.states.CONN_FAIL_XFER
log.error('ERROR: POST returned a status of %d', status)
return False
info('HTTP POST response status %d', status)
except IncompleteRead:
if ydata != '':
raise
except:
ydata != ''
finally:
conn.close()
self.state = self.states.FINISHED
self._ondone()
return True
_post_file = threaded(_post_file)
class YahooIconSender(OutgoingYHTTPXfer):
def __repr__(self):
return '<YahooIconSender>'
def send_buddy_icon(cls, protocol, image_data):
Image = Image
import PIL
i = Image.open(StringIO(image_data))
if image_data[:8] != PNG_HEADER or i.size != (96, 96):
converted = StringIO()
i2 = i.Resized(96)
i2.save(converted, 'PNG')
image_data = converted.getvalue()
xfer = YahooIconSender(protocol, initiate = False)
selfname = protocol.self_buddy.name
filesize = len(image_data)
ydata = protocol.yahoo_packet_v(15, 'picture_upload', 'available', 'frombuddy', selfname, 'expires', struct.pack('6s', '604800'), 'away_buddy', selfname, 'filesize', filesize, 'filename', 'myicon.png', 'message', ' ', 'filedata', '')
sublen = (struct.unpack('!H', ydata[8:10])[0] - 8 + len(str(filesize))) + 14
ydata = ydata[:8] + struct.pack('!H', sublen - 1) + ydata[10:-2]
xfer.state = xfer.states.TRANSFERRING
log.info('sending %d bytes of image data', filesize)
xfer._post_file(ydata, protocol.cookie_str, fileobj = StringIO(image_data), filesize = filesize)
send_buddy_icon = classmethod(send_buddy_icon)
def _ondone(self):
self.setnotifyif('state', self.states.FINISHED)
self._done = True
def on_error(self):
log.critical('error sending icon')